<template>
	<view class="content">
		<web-view id="wv" @message="message" @onPostMessage="message1" :src="src"></web-view>
		<bgyx-tab-bar />
	</view>


</template>

<script>
	import config from '../../config.js'
	import {
		mapState
	} from 'vuex';
	import {
		pub
	} from '../../common/event';
import moment from 'moment/moment';
	export default {
		data() {
			return {
				name: '',
				context: '',
				wv:'',
				src:''
			}
		},
		components: {

		},
		computed: {
			...mapState({

			})
		},
		onLoad() {
			this.src = `/hybrid/html/v.html?uid=1&uname=2&name=3&id=4&ip=${config.ip}&srsUrl=${encodeURIComponent(config.srsUrl)}`
		},
		onReady() {
			// #ifdef APP
			let currentWebview = this.$scope.$getAppWebview();
			this.wv = currentWebview.children()[0]
			setInterval(()=>{
				this.sendMessage({
					type:"bbggyyxx",
					time:moment().valueOf()
				})
			},5000)
			// #endif
			// #ifdef H5
			// 监听数据
			window.addEventListener("message", function(e) {
				console.log("YY11YY",e)
			})
			setTimeout(()=>{
				this.sendMessage({
					action:'towv',
					type:"bbggyyxx",
					time:moment().valueOf()
				})
			},5000)
			// #endif
		},
		methods: {
			sendMessage(data) {
				// #ifdef APP
				const message = JSON.stringify(data)
				if (!this.wv) {
					let currentWebview = this.$scope.$getAppWebview();
					this.wv = currentWebview.children()[0]
				}
				this.wv.evalJS(`vm.onMessage(${message})`);
				// #endif
				
				// #ifdef H5
				const message = JSON.stringify(data)
				console.log(message)
				window.postMessage(message)
				// #endif
			},
			message:function(e){
				console.log(111,e)
			},
			message1:function(e){
				console.log(222,e)
			},
		}
	}
</script>


<style scoped>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 100%;
		height: 100vh;
		overflow-y: hidden;
		padding-bottom: 120rpx;
		border-start-end-radius: 32rpx;
		border-start-start-radius: 32rpx;
	}
</style>